package abacab.router;

import abacab.actor.Actor;
import abacab.actor.ActorDef;
import abacab.exec.MessageExecutor;
import abacab.message.Envelope;
import abacab.ref.AbstractActorRef;

/**
 * A router that has only a single actor
 * 
 * @param <M>
 *          the type of handled messages
 */
public class NoRouter<M> extends AbstractRouter<M> {
	/** The actor */
	private Actor<? super M>	actor;

	@Override
	public void init(AbstractActorRef<M> actorRefP, ActorDef<M> definitionP) {
		super.init(actorRefP, definitionP);
		this.actor = buildActor("@");
		this.actor.init();
	}

	@Override
	@SuppressWarnings("unchecked")
	public Actor<? super M>[] getActors() {
		return new Actor[] { this.actor };
	}

	@Override
	public void send(MessageExecutor executor, Envelope<M> message) {
		this.actor.getActorContext().getQueue().offer(message);
		executor.queueForExecution(this.actor);
	}
}